package com.sinoglobal.wallet.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class NoDefaultPaddingTextView extends TextView {
	
	private Paint mPaint;
	private Rect mRect;

	public NoDefaultPaddingTextView(Context context) {
		super(context);
	}

	public NoDefaultPaddingTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		String text = getText().toString();
		if(mPaint == null) {
			ColorStateList textColors = getTextColors();
			int defaultColor = textColors.getDefaultColor();
			float textSize = getTextSize();
			mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
			mPaint.setTextSize(textSize);
			mPaint.setColor(defaultColor);
			mRect = new Rect();
			mPaint.getTextBounds(text, 0, text.length(), mRect);
		}
		canvas.drawText(text, 0, getMeasuredHeight() - mRect.bottom, mPaint);
	}

}